home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.747 < prev    next >
Text File  |  1992-02-06  |  3KB  |  78 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Ohlfs;\f2\fswiss Helvetica;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 appending text font\
  8. \
  9. Q:  How do I append text to a text object, such that the new text has a different font?\
  10. \
  11. A:  First of all, make sure that the text object can contain multiple fonts. Send the following message to your text object:\
  12. \
  13.  
  14. \f1\fs22     id myText;\
  15.     ...\
  16.     [myText setMonoFont:NO];\
  17.     ...\
  18.  
  19. \f0\fs28 \
  20. Then, use the following code snippet to append the text, select the text, and change its font:\
  21. \
  22.  
  23. \f1\fs22     id myText;\
  24.     int length;\
  25.     \
  26.     ...\
  27.     length = [myText textLength];\
  28.     [myText setSel:length:length];    // put an empty selection at the end of the text\
  29.  
  30. \fc0     [myText replaceSel:"some new text"];    // add some text\
  31.     [myText setSel:(length-1):[self textLength]];    // select the newly added text\
  32.     [myText setSelFont:
  33. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 [Font newFont:"Symbol" size:
  34. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 24.0
  35. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 ]
  36. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 ];    // change its font\
  37.     ...\
  38.  
  39. \f0\fs28         \
  40. The following code snippet 
  41. \b will not work 
  42. \b0 due to the way in which setSelFont:, and replaceSel: interact:\
  43. \
  44.  
  45. \f1\fs22     id myText;\
  46.     int length;\
  47.     \
  48.     ...\
  49.     length = [myText textLength];\
  50.     [myText setSel:length:length];    // put an empty selection at the end of the text\
  51.     [myText setSelFont:
  52. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 [Font newFont:"Symbol" size:
  53. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 24.0
  54. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 ]
  55. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 ];    // change the font\
  56.     [myText replaceSel:"some new text"];    // add some text\
  57.     ...\
  58.  
  59. \f0\fs28         \
  60. To avoid some of the flashing that may occur to the text object while selecting and modifying the font programmatically, you should perform a 
  61. \b disableDisplay
  62. \b0  on the window containing the text object before selecting and modifying the text. After the modifications you should then 
  63. \b reenableDisplay
  64. \b0  on the window and 
  65. \b display
  66. \b0  the text object. See NeXTanswers appkit.710 for more information about 
  67. \b disableDisplay.
  68. \b0 \
  69. \
  70. For more information about appending text to a text object see NeXTanswer appkit.396.\
  71. \
  72. QA747\
  73. \
  74. Valid for 1.0\
  75. Valid for 2.0\
  76. \
  77.  
  78.